import pymysql

class DBTools(object):

    @classmethod
    def __create_conn(cls):
        conn = pymysql.connect(host="211.103.136.244", port=7061, user="student",
                               password="iHRM_student_2021", database="ihrm", charset="utf8")
        return conn

    @classmethod
    def query_one(cls,sql):
        conn =None
        cursor = None
        res = None
        try:
            conn = DBTools.__create_conn()
            cursor = conn.cursor()
            cursor.execute(sql)
            res = cursor.fetchone()
        except Exception as e:
            print("sql语句执行错误")
        finally:
            cursor.close()
            conn.close()
            return res

    @classmethod
    def uid(cls,sql):
        conn = None
        cursor = None
        try:
            conn = DBTools.__create_conn()
            cursor = conn.cursor()
            cursor.execute(sql)
            conn.commit()
        except Exception as e:
            print("sql语句执行错误")
            conn.rollback()
        finally:
            cursor.close()
            conn.close()



